package com.xm.xmapp.base;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.myinterface.ListViewOnclickInterFace;

public abstract class MyBaseAdapter<T> extends BaseAdapter {

	public ArrayList<T> list;
	public Context activity;
	public int layoutId;
	public ListViewOnclickInterFace in;

	public void setIn(ListViewOnclickInterFace listViewOnclickInterFace) {
		this.in = listViewOnclickInterFace;
	}

	public MyBaseAdapter(ArrayList<T> list, Activity activity, int layoutId) {
		super();
		this.list = list;
		this.activity = activity.getApplicationContext();
		this.layoutId = layoutId;
	}
	
	public void setData(ArrayList<T> list)
	{
		this.list = list;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return list==null?0:list.size();
	}

	@Override
	public T getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = ViewHolder.getViewHolder(MyAppcation.getMyAppcation(), convertView,
				parent, layoutId, position);
		setValues(holder,list.get(position),position);
		return holder.getConvertView();
	}

	public abstract void setValues(ViewHolder holder , T t ,int position);
}
